<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>1</title>
</head>

<body>
    <input id="name" type="text">
    <button id="submit-btn">Submit</button>
</body>

<script>
    window.onload = function () {
        var btn = document.getElementById("submit-btn");
        var input = document.getElementById("name");

        function ClickBtn(event) {
            console.log(input.value);
        }

        function KeyDown(e) {
            if (e.keyCode == 13) {
                var input = document.getElementById("name");
                console.log(input.value);
            } else if (e.keyCode == 27) {
                var input = document.getElementById("name");
                input.value = "";
            }
        }

        btn.addEventListener("click", ClickBtn);
        input.addEventListener("keydown", KeyDown);
    }
</script>

</html>